#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :pixelcut_requests.py
# @Time      :2024/11/5 
# @Author    :CL
# @email     :1037654919@qq.com
# https://www.pixelcut.ai/t/background-remover
# 使用requests  失败 ，换用DrissionPage

import requests
proxies ={'http': 'http://127.0.0.1:7897',
          'https': 'http://127.0.0.1:7897'}
headers = {
        "authority": "api2.pixelcut.app",
        "method": "POST",
        "path": "/image/matte/v1",
        "scheme": "https",
        "accept": "*/*",
        "accept-language": "zh-CN,zh;q=0.9",
        "cache-control": "no-cache",
        "content-type": "application/x-www-form-urlencoded",
        "origin": "https://www.pixelcut.ai",
        "pragma": "no-cache",
        "priority": "u=1, i",
        "referer": "https://www.pixelcut.ai/",
        "sec-ch-ua": "\"Google Chrome\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\"",
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": "\"Linux\"",
        "sec-fetch-dest": "empty",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "cross-site",
        "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
        ,'x-client-version':'web'
    }
with open("9762029.jpg","rb") as f:
    files = {
        'image': ("9762029.jpg",f, 'image/jpeg')  # 文件名，文件对象，文件类型
    }


    url = "https://api2.pixelcut.app/image/matte/v1"

    data = {
        # 'image': (f) , # 文件名，文件对象，文件类型
        'format':'png',
        'model':'v1'
    }
    response = requests.post(url, headers=headers,proxies=proxies,data=data,files=files,timeout=10)

    print(response.text)
    print(response)